<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="utf-8">
        <title>
            	
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/houtaistatic/css/x-admin.css" media="all">
    </head>


    <script src="/houtaistatic/js/jquery.min.js" type="text/javascript"></script>
 <!--   使用ajax异步刷新技术-->
    <script type="text/javascript">
        $(function () {
            $("#add").click(function () {
                if(confirm("确认添加嘛")){
                    var typeNamevar = document.getElementById("typeNamevar");
                    if(typeNamevar.validity.valueMissing==true){
                        typeNamevar.setCustomValidity("名称不能为空");
                        return;
                    }else{
                        typeNamevar.setCustomValidity("");
                    }
                  //  alert(typeNamevar.value);
                    $.ajax({
                        url: "/traveltype/add?typeName="+typeNamevar.value,
                        type: "POST",
                        dataType: "text",
                        error:function(){
                            alert("添加失败");

                        },
                        success: function(data) {
                            if(data=="0"){
                                alert("添加失败")
                            } else if(data=="-2"){
                                alert("类型已存在");
                            }else{
                                alert("添加成功！");
                                typeNamevar.value="";
                                $("#x-link").append("<tr><td><input type='checkbox' value='1' name=''></td><td >"+data.id+"</td><td >"+data.typeName+"</td><td >"+data.createTime+"</td><td class='td-manage'><a title='删除' href='#' onclick='commemt_del(this,)' class='delete' dataid='"+data.id+"' style='text-decoration:none'><i class='layui-icon'>&#xe640;</i></a></td></tr>")

                            }
                        }
                    });
                }
            });
            $(".delete").click(function () {
                var deleteid = $(this).attr("dataid");
                var index  =$(".delete").index(this);
               // alert(index);
                if(confirm("确定是否删除？？？？")){
                    $.ajax({
                        url: "/traveltype/deleteByid?id="+deleteid,
                        type: "POST",
                        dataType: "text",
                        error:function(){
                            alert("删除失败");

                        },
                        success: function(data) {
                            if(data=="0"){
                                alert("删除失败")
                            } else if(data=="-2"){
                                alert("抱歉有其他行程引用此类型不能做此操作");
                            }else{
                                alert("删除成功");
                                $('table tr').eq(index).remove();
                            }
                        }
                    });
                }
            });
        });
    </script>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>旅游类型管理</cite></a>
              <a><cite>一级类型</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">
            <form class="layui-form x-center" style="width:800px">
                <div class="layui-form-pane" style="margin-top: 15px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">类型名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="typeNamevar"  id="typeNamevar"  placeholder="请输入类型名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:80px">
                            <button class="layui-btn" id="add"><i class="layui-icon">&#xe608;</i>添加</button>
                        </div>
                    </div>
                </div>
            </form>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" name="" value="">
                        </th>
                        <th>
                            编号
                        </th>
                        <th>
                            名称
                        </th>
                        <th>
                            创建时间
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody id="x-link">
                    <tr th:each="emp : ${fulist}">
                        <td>
                            <input type="checkbox" value="1" name="">
                        </td>
                        <td th:text="${emp.id}">
                            1
                        </td>
                        <td th:text="${emp.typeName}">
                            二当家的
                        </td>
                        <td th:text="${emp.createTime}">

                        </td>
                        <td class="td-manage">
                            <a title="删除" href="#" onclick="commemt_del(this,)" class="delete"  th:dataid="${emp.id}"
                            style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div id="page"></div>
        </div>
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script src="./js/x-layui.js" charset="utf-8"></script>

    </body>
</html>